home *** CD-ROM | disk | FTP | other *** search
Text File | 1996-09-14 | 6.6 KB | 227 lines | [TEXT/CWIE] |
- // ===========================================================================
- // File: LEnhancedEditField.cp
- // Version: 1.0 - Feb 08,1996
- // Author: Mike Shields (mshields@inconnect.com)
- //
- // Copyright ©1996 Mike Shields. All rights reserved.
- // I hereby grant users of LEnhancedEditField permission to use it (or any modified
- // version of it) in applications (or any other type of Macintosh software
- // like extensions -- freeware, shareware, commercial, or other) for free,
- // subject to the terms that:
- //
- // (1) This agreement is non-exclusive.
- //
- // (2) I, Mike Shields, retain the copyright to the original source code.
- //
- // These two items are the only required conditions for use. However, I do have
- // an additional request. Note, however, that this is only a request, and
- // that it is not a required condition for use of this code.
- //
- // (1) That I be given credit for LEnhancedEditField code in the copyrights or
- // acknowledgements section of your manual or other appropriate documentation.
- //
- //
- // I would like to repeat that this last item is only a request. You are prefectly
- // free to choose not to do any or all of them.
- //
- // This source code is distributed in the hope that it will be useful,
- // but WITHOUT ANY WARRANTY; without even the implied warranty of
- // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
- // ===========================================================================
- // LEnhancedEditField.h <- double-click + Command-D to see class declaration
- //
- //
- // LEditField which properly dims itself when disabled
- #include "LEnhancedEditField.h"
-
- #include <LStream.h>
- #include <UDrawingState.h>
- #include <UDrawingUtils.h>
-
- #ifndef __QUICKDRAW__
- #include <Quickdraw.h>
- #endif
- // ---------------------------------------------------------------------------
- // • CreateEditFieldStream
- // ---------------------------------------------------------------------------
- // Create a new EditField object from the data in a Stream
-
- LEnhancedEditField*
- LEnhancedEditField::CreateEditFieldStream(LStream *inStream)
- {
- return (new LEnhancedEditField(inStream));
- }
-
-
- // ---------------------------------------------------------------------------
- // • LEnhancedEditField
- // ---------------------------------------------------------------------------
- // Default Constructor
-
- LEnhancedEditField::LEnhancedEditField()
- {
- }
-
-
- // ---------------------------------------------------------------------------
- // • LEnhancedEditField(LEnhancedEditField&)
- // ---------------------------------------------------------------------------
- // Copy Constructor
-
- LEnhancedEditField::LEnhancedEditField(
- const LEnhancedEditField &inOriginal)
- : LEditField(inOriginal)
- {
- }
-
-
- // ---------------------------------------------------------------------------
- // • LEnhancedEditField
- // ---------------------------------------------------------------------------
- // Construct from input parameters
-
- LEnhancedEditField::LEnhancedEditField(
- const SPaneInfo &inPaneInfo,
- Str255 inString,
- ResIDT inTextTraitsID,
- Int16 inMaxChars,
- Boolean inHasBox,
- Boolean inHasWordWrap,
- KeyFilterFunc inKeyFilter,
- LCommander *inSuper)
- : LEditField(inPaneInfo, inString, inTextTraitsID, inMaxChars,
- inHasBox, inHasWordWrap, inKeyFilter, inSuper)
- {
- }
-
-
- LEnhancedEditField::LEnhancedEditField(
- const SPaneInfo &inPaneInfo,
- Str255 inString,
- ResIDT inTextTraitsID,
- Int16 inMaxChars,
- Uint8 inAttributes,
- KeyFilterFunc inKeyFilter,
- LCommander *inSuper)
- : LEditField(inPaneInfo, inString, inTextTraitsID, inMaxChars, inAttributes,
- inKeyFilter, inSuper)
- {
- }
-
-
- // ---------------------------------------------------------------------------
- // • LEnhancedEditField(LStream*)
- // ---------------------------------------------------------------------------
- // Construct an EditField from the data in a Stream
-
- LEnhancedEditField::LEnhancedEditField(
- LStream *inStream)
- : LEditField(inStream)
- {
- }
-
-
- // ---------------------------------------------------------------------------
- // • ~LEnhancedEditField
- // ---------------------------------------------------------------------------
- // Destructor
-
- LEnhancedEditField::~LEnhancedEditField()
- {
- }
-
- // ---------------------------------------------------------------------------
- // • DrawBox
- // ---------------------------------------------------------------------------
- // Draw box around an EditField. Overidden to NOT draw in grey patern when disabled.
-
- void
- LEnhancedEditField::DrawBox()
- {
- // Box around an EditField is outset from the Text by 2 pixels.
- // The box itself is 1 pixel thick, drawn in the foreground color
- // of the Pane (not necessarily the same as the text color).
- //
- // The 1 pixel rectangle between the box and the text draws in
- // the background color of the text.
- StColorState saveColors; // Preserve color state
- Rect frame;
- CalcLocalFrameRect(frame);
- ::PenNormal();
-
- // Draw empty area between Box and Text. On entry, the fore
- // and back colors for the Text are in effect (as set in FocusDraw).
- // Use Text back color as the fore color for the empty area.
- ::InsetRect(&frame, 1, 1);
- RGBColor emptyColor;
- ::GetBackColor(&emptyColor);
- ::RGBForeColor(&emptyColor);
- ::FrameRect(&frame);
-
- // Draw border around EditField
- ::InsetRect(&frame, -1, -1);
-
- ApplyForeAndBackColors();
- ::FrameRect(&frame);
- }
-
- // ---------------------------------------------------------------------------
- // • DrawSelf
- // ---------------------------------------------------------------------------
- // Draw an EditField
-
- void
- LEnhancedEditField::DrawSelf()
- {
- // draw ourseleves like normal,
- LEditField::DrawSelf();
-
- // now paint over ourselves to make ourselves reflect our
- // disabled-ness.
- if ( mEnabled != triState_On )
- {
- Rect frame;
- CalcLocalFrameRect(frame);
-
- StDeviceLoop theLoop(frame);
- Int16 depth;
-
- while ( theLoop.NextDepth(depth) )
- {
- if (depth >= 4)
- {
- PaintDisabled(&frame);
- }
- else
- {
- StColorPenState savedPenState;
-
- PenMode(patBic);
- PenPat(&qd.gray);
- PaintRect(&frame);
- }
- }
- }
- }
-
- // ---------------------------------------------------------------------------
- // • PaintDisabled
- // ---------------------------------------------------------------------------
- // Paint over ourselves with the proper settings to "grey out" our previous drawing.
- void LEnhancedEditField::PaintDisabled(Rect *inDrawRect)
- {
- StColorPenState savedPenState;
- RGBColor newRGBColor,
- newOpColor;
-
- newOpColor.red = newOpColor.blue = newOpColor.green = 0x7530;
- newRGBColor.red = newRGBColor.blue = newRGBColor.green = 0xFFFF;
-
- ::OpColor(&newOpColor);
- ::RGBForeColor(&newRGBColor);
- ::PenMode(blend);
- ::PenPat(&qd.black);
- ::PaintRect(inDrawRect);
- }
-
-